/**
 * @file
 * Expansion graph instance test
 */

#include "expansion_graph_instance_ops_test.h"

#include "multimap_comparison.h"
#include "string_vertex_edge.h"
#include "expansion_graph_instance_ops.h"

void ExpansionGraphInstanceOpsTest::SetUp()
{
  ExpansionGraphInstanceTest::SetUp();
}

void ExpansionGraphInstanceOpsTest::TearDown()
{
    ExpansionGraphInstanceTest::TearDown();
}

TEST_F(ExpansionGraphInstanceOpsTest, GetInstanceVertexMapping)
{
  std::multimap<StringVertexEdge*, StringVertexEdge*> actual;
  get_instance_vertex_mapping(g1_i1, g1_i2, &actual);

  std::multimap<StringVertexEdge*, StringVertexEdge*> expected;
  expected.insert(std::pair<StringVertexEdge*, StringVertexEdge*> (g1_v1, g1_v1));
  expected.insert(std::pair<StringVertexEdge*, StringVertexEdge*> (g1_v8, g1_v7));
  expected.insert(std::pair<StringVertexEdge*, StringVertexEdge*> (g1_v8, g1_v8));
  expected.insert(std::pair<StringVertexEdge*, StringVertexEdge*> (g1_v9, g1_v7));
  expected.insert(std::pair<StringVertexEdge*, StringVertexEdge*> (g1_v9, g1_v8));
  EXPECT_TRUE(multimap_compare(actual,expected));
}  
  
TEST_F(ExpansionGraphInstanceOpsTest, CheckInstanceVertexMapping)
{
  std::map<StringVertexEdge*, StringVertexEdge*> input_mapping1;
  input_mapping1.insert(std::pair<StringVertexEdge*, StringVertexEdge*> (g1_v1, g1_v1));
  input_mapping1.insert(std::pair<StringVertexEdge*, StringVertexEdge*> (g1_v8, g1_v7));
  input_mapping1.insert(std::pair<StringVertexEdge*, StringVertexEdge*> (g1_v9, g1_v8));
  EXPECT_TRUE(check_instance_mapping(g1_i1, g1_i2, &input_mapping1));

  std::map<StringVertexEdge*, StringVertexEdge*> input_mapping2;
  input_mapping2.insert(std::pair<StringVertexEdge*, StringVertexEdge*> (g1_v1, g1_v1));
  input_mapping2.insert(std::pair<StringVertexEdge*, StringVertexEdge*> (g1_v9, g1_v7));
  input_mapping2.insert(std::pair<StringVertexEdge*, StringVertexEdge*> (g1_v8, g1_v8));
  EXPECT_TRUE(check_instance_mapping(g1_i1, g1_i2, &input_mapping2));

  std::map<StringVertexEdge*, StringVertexEdge*> input_mapping3;
  input_mapping3.insert(std::pair<StringVertexEdge*, StringVertexEdge*> (g1_v9, g1_v1));
  input_mapping3.insert(std::pair<StringVertexEdge*, StringVertexEdge*> (g1_v1, g1_v7));
  input_mapping3.insert(std::pair<StringVertexEdge*, StringVertexEdge*> (g1_v8, g1_v8));
  EXPECT_FALSE(check_instance_mapping(g1_i1, g1_i2, &input_mapping3));

  std::map<StringVertexEdge*, StringVertexEdge*> input_mapping4;
  input_mapping4.insert(std::pair<StringVertexEdge*, StringVertexEdge*> (g1_v8, g1_v1));
  input_mapping4.insert(std::pair<StringVertexEdge*, StringVertexEdge*> (g1_v9, g1_v7));
  input_mapping4.insert(std::pair<StringVertexEdge*, StringVertexEdge*> (g1_v1, g1_v8));
  EXPECT_FALSE(check_instance_mapping(g1_i1, g1_i2, &input_mapping4));
}

TEST_F(ExpansionGraphInstanceOpsTest, MatchVertices)
{
  EXPECT_TRUE(match_instance_vertices(g1_v1, g1_v1, g1_i1, g1_i2));
  EXPECT_TRUE(match_instance_vertices(g1_v8, g1_v8, g1_i1, g1_i2));
  EXPECT_TRUE(match_instance_vertices(g1_v8, g1_v7, g1_i1, g1_i2));
  EXPECT_TRUE(match_instance_vertices(g1_v9, g1_v7, g1_i1, g1_i2));
  EXPECT_TRUE(match_instance_vertices(g1_v9, g1_v8, g1_i1, g1_i2));

  EXPECT_TRUE(match_instance_vertices(g1_v1, g1_v1, g1_i2, g1_i1));
  EXPECT_TRUE(match_instance_vertices(g1_v8, g1_v8, g1_i2, g1_i1));
  EXPECT_TRUE(match_instance_vertices(g1_v8, g1_v9, g1_i2, g1_i1));
  EXPECT_TRUE(match_instance_vertices(g1_v7, g1_v8, g1_i2, g1_i1));
  EXPECT_TRUE(match_instance_vertices(g1_v7, g1_v9, g1_i2, g1_i1));


  EXPECT_FALSE(match_instance_vertices(g1_v1, g1_v7, g1_i1, g1_i2));
  EXPECT_FALSE(match_instance_vertices(g1_v1, g1_v8, g1_i1, g1_i2));
  EXPECT_FALSE(match_instance_vertices(g1_v1, g1_v8, g1_i1, g1_i2));
  EXPECT_FALSE(match_instance_vertices(g1_v8, g1_v9, g1_i1, g1_i2));

  EXPECT_FALSE(match_instance_vertices(g1_v7, g1_v1, g1_i1, g1_i2));
  EXPECT_FALSE(match_instance_vertices(g1_v8, g1_v1, g1_i1, g1_i2));
  EXPECT_FALSE(match_instance_vertices(g1_v8, g2_v1, g1_i1, g1_i2));
  EXPECT_FALSE(match_instance_vertices(g1_v9, g2_v8, g1_i1, g1_i2));
}
